package com.mark.web.stars.entity.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mark.common.Constant;
import com.mark.common.utils.PropertiesUtil;
import com.mark.web.stars.entity.po.Fragment;
import com.mark.web.stars.enums.FragmentEnum;
import com.mark.web.sys.entity.po.User;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @Description: 碎片的VO类
 * @Author: Mark
 * @CreateDate: 2019/6/2 18:08
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@Data
public class FragmentVo {


    /**
     * 主键id
     */
    private Integer id;

    /**
     * 逻辑外键，所属类型id
     */
    private Integer fkTypeId;

    /**
     * 逻辑外键，所属用户id
     */
    private Integer fkUserId;

    /**
     * 内容
     */
    private String content;

    /**
     * 状态:1:私密-2：公开
     */
    private String status;

    /**
     * 被喜欢的个数
     */
    private Integer liked;

    /**
     * 图片地址
     */
    private String imgAddress;

    /**
     * 所属用户名
     */
    private String ownerName;

    /**
     * 所属用户的头像地址
     */
    private String ownerImagesAddress;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date createTime;

    /**
     * 上一次的修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date lastEditTime;

    /**
     * 通过构造函数实例化vo
     */
    public FragmentVo(Fragment fragment, User user) {
        //基本信息的赋值
        this.id = fragment.getId();
        this.fkUserId = fragment.getFkUserId();
        this.fkTypeId = fragment.getFkTypeId();
        this.content = fragment.getContent();
        this.status = FragmentEnum.stateOf(fragment.getStatus());
        this.liked = fragment.getLiked();

        //碎片图片资源地址的处理
        if(StringUtils.isNotBlank(fragment.getImgAddress())){
            this.imgAddress = Constant.CampusProperties.IMAGE_HOST +fragment.getImgAddress();
        }else{
            this.imgAddress = StringUtils.EMPTY;
        }
        this.createTime = fragment.getCreateTime();
        this.lastEditTime = fragment.getLastEditTime();

        //碎片所属的用户的信息赋值
        this.ownerName = user.getUsername();
        if(Constant.CampusProperties.UPLOAD_FILE_TYPE.equals(1)){
            //文件直接保存到本地服务器
            this.ownerImagesAddress = Constant.CampusProperties.IMAGE_HOST+user.getUserImg();
        }else{
            this.ownerImagesAddress = "未知！！";
        }

    }
}
